package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Ill;
import com.itheima.service.IllService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/ill")
@RestController
public class IllController {
    @Reference
    private IllService illService;

    @RequestMapping("/add")
    public Result addSport(@RequestBody Ill ill) {
        try {
            illService.add(ill);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "添加疾病失败");
        }
        return new Result(true, "添加疾病成功");
    }

    //分页查询、
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return illService.findPage(queryPageBean);
    }

    //编辑
    @RequestMapping("/edit")
    public Result edit(@RequestBody Ill ill){
        try {
            illService.edit(ill);
            return new Result(true,"编辑疾病库成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"编辑疾病库失败");
        }
    }
    @RequestMapping("findById")
    private Result findById(Integer id){
        try {
            Ill ill= illService.findById(id);
            return new Result(true,"查询疾病成功",ill);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查询疾病失败");
        }
    }

    @RequestMapping("/delete")
    public Result delete(Integer id){
        try {
            illService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"删除疾病失败");
        }
        return new Result(true,"删除疾病失败");
    }
}
